//引用公共函数文件
var user_remote_info_fun = require("user_remote_info.js");
var app = getApp();
module.exports.getWeiXinInfo = getWeiXinInfo;
module.exports.getWeiXinInfo_Back = getWeiXinInfo_Back;
//获取授权后数据
function getWeiXinInfo() {
  wx.getUserInfo({
    success: function (res) {
      var app = getApp();
      app.globalData.getUserInfoFail = false;
      module.exports.getWeiXinInfo_Back(res);
    },
    fail:function(res){
      var app = getApp();
      app.globalData.getUserInfoFail = true;
      module.exports.getWeiXinInfo_Back("fail");
    }
  });
}

//数据回调
function getWeiXinInfo_Back(res) {
  //获取应用实例
  var app = getApp();
  if (res == "fail"){
    app.globalData.getUserInfoFail = true;
    app.globalData.userInfo["nickname"] = "";
    app.globalData.userInfo["sex"] = 3;
    app.globalData.userInfo["country"] = "";
    app.globalData.userInfo["city"] = "";
    app.globalData.userInfo["province"] = "";
    app.globalData.userInfo["language"] = "";
    app.globalData.userInfo["headimgurl"] = "http://mp.87apk.com/public/me2.png";
  }else{
    app.globalData.getUserInfoFail = false;
    app.globalData.userInfo["nickname"] = res.userInfo["nickName"];
    app.globalData.userInfo["sex"] = res.userInfo["gender"];
    app.globalData.userInfo["country"] = res.userInfo["country"];
    app.globalData.userInfo["city"] = res.userInfo["city"];
    app.globalData.userInfo["province"] = res.userInfo["province"];
    app.globalData.userInfo["language"] = res.userInfo["language"];
    app.globalData.userInfo["headimgurl"] = res.userInfo["avatarUrl"];
  }
  user_remote_info_fun.getRemoteUserInfo();
}


